
<template>

    <div class="toteacher">
  
        <div class="sousuo">
            <p>关键字</p>
            <el-input v-model="input" placeholder="工号/姓名/手机"></el-input>
            <el-button type="primary" icon="el-icon-search" @click="onSearch"></el-button>

        </div>
        <div class="table">
            <el-button icon="el-icon-star-off" @click="dialogVisible = true">点击添加</el-button>

            <!-- 对话框 -->
            <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
                <el-form ref="form" :model="form" label-width="80px">
                    <el-form-item label="姓名">
                        <el-input v-model="form.name"></el-input>
                    </el-form-item>
                    <el-form-item label="工号">
                        <el-input v-model="form.tid"></el-input>
                    </el-form-item>
                    <el-form-item label="手机">
                        <el-input v-model="form.phone"></el-input>
                    </el-form-item>
                    <el-form-item label="qq">
                        <el-input v-model="form.qq"></el-input>
                    </el-form-item>
                    <el-form-item label="性别">
                        <el-input v-model="form.sex"></el-input>
                    </el-form-item>

                </el-form>


                <span slot="footer" class="dialog-footer">
                    <el-button @click="dialogVisible = false">取 消</el-button>
                    <el-button type="primary" @click="onEnit" v-if="form.id"> 编辑</el-button>
                    <el-button type="primary" @click="onSubmit" v-else> 添加</el-button>

                </span>
            </el-dialog>
            <template>
                <el-table :data="tableData" border style="width: 100%">
                    <el-table-column prop="id" width="60" align="center">
                    </el-table-column>
                    <el-table-column prop="name" label="姓名" width="205">
                    </el-table-column>
                    <el-table-column prop="tid" label="工号" width="205">
                    </el-table-column>
                    <el-table-column prop="phone" label="手机" width="205">
                    </el-table-column>
                    <el-table-column prop="qq" label="qq" width="205">
                    </el-table-column>
                    <el-table-column prop="sex" label="性别" width="205">
                    </el-table-column>
                    <el-table-column prop="hand" label="操作" width="240">
                        <template slot-scope="scope">
                            <el-button size="mini" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                            <el-button size="mini" style=" backgroundColor: rgb(255,184,0);"
                                @click="handleReport(scope.$index, scope.row)">发布成绩</el-button>
                            <el-button size="mini" type="danger"
                                @click="handleDelete(scope.$index, scope.row)">删除</el-button>
                        </template>
                    </el-table-column>
                </el-table>
            </template>
        </div>
        <div class="footer">

            Cepyright c2022

        </div>


    </div>
</template>

<script>


import * as service from "../../api/index";
export default {

    data() {
        return {
            tableData: [],
            input: "",
            crumbList: [],

            dialogVisible: false,
            form: {
                id: "",
                name: "",
                tid: "",
                phone: "",
                qq: "",
                sex: "",
                hand: "",
            }
        }
    },

    mounted() {
        service.teacherlist().then((res) => {
            // console.log(res);
            this.tableData = res.data
        })
    },


    methods: {
        handleReport(index, row) {
            console.log(index, row);
        },
        handleEdit(index, row) {
            console.log(row);
            this.dialogVisible = true;
            this.form = row

        },
        handleDelete(index, row) {
            console.log(index, row);
            service.teacher_delete({ id: row.id }).then((res) => {
                if (res) {
                    this.$message('删除成功！！！！');
                    service.teacherlist().then((res) => {
                        this.tableData = res.data
                    })

                }

            })
        },
        onSearch() {
            console.log(this.input);
            service.teacherlist({ phone: this.input }).then((res) => {
                // console.log(res);
                this.tableData = res.data
                if (Object.keys(res.data).length == 0) {
                    service.teacherlist().then((res) => {
                        // console.log(res);
                        this.tableData = res.data
                    })
                }
            })
        },

        onSubmit() {
            service.teacher_add(this.form).then((res) => {
                console.log(res);
                if (res) {
                    this.$message('添加成功！！！！');
                    this.dialogVisible = true
                }
                service.teacherlist().then((res) => {
                    this.tableData = res.data
                })

            })

        },
        onEnit() {
            console.log(this.form);
            service.teacher_update({id:this.form.id,name:this.form.name,
                tid:this.form.tid,phone:this.form.phone,qq:this.form.qq,sex:this.form.sex,
            }).then((res) => {
                console.log(res)
                if (res) {
                    this.$message('编辑成功！！！！');
                    this.dialogVisible=false
                    service.teacherlist().then((res) => {
                        this.tableData = res.data
                    })
                }
            })
        }
    }
}
</script>

<style lang="scss" scoped>
.mianbao {
    height: 48px !important;
    width: 100%;
    padding: 16px 20px;
    background-color: #fff;
}

.footer {
    height: 48px !important;
    width: 100%;
    padding: 16px 20px;
    background-color: #fff;
    margin-top: 20px;
}

.sousuo {
    display: flex;
    background-color: #fff;
    margin: 20px 10px 0;
    padding: 20px;

    p {
        line-height: 40px;
        margin-right: 5px;
    }

    .el-button--primary {
        height: 40px;
        width: 40px;
        line-height: 40px;
        padding: 0;
        background-color: rgb(14, 155, 142);
        border-color: rgb(14, 155, 142);
    }

    .el-input {
        width: 200px !important;

    }

    .el-input__inner {
        border-radius: 0px !important;
        margin-left: 44px !important;

    }
}

.table {
    background: #fff;
    padding: 16px 20px;
    margin: 20px 10px 0;

    .el-button--default {
        float: left;
        margin-bottom: 20px;
        background-color: rgb(14, 155, 142);
        color: #fff;
    }

    .has-gutter {
        background-color: rgb(228, 228, 228) !important;
        height: 40px;
    }
}
</style>